//
//  peopleMesViewController.m
//  day1
//
//  Created by 于跃隆 on 2020/4/8.
//  Copyright © 2020 于跃隆. All rights reserved.
//

#import "peopleMesViewController.h"
#import "QuitView.h"
#import "infoModel.h"
#import "PickerView.h"
#import "MyInfoModel.h"

@interface peopleMesViewController ()<UITableViewDelegate , UITableViewDataSource,UITextViewDelegate>{
    UIView *jbTview;
    UIImageView     *TouiamgeImageV;
    
    //导航条title
    UILabel *navtitle;
    
    //存储的string
    NSString *userName;
    NSString *userGender;
    NSString *userAge;
    NSString *educationGraduationYear;
    NSString *educationSchool;
    NSString *workExperience;
    NSString *selfEvaluation;
}

//表格
@property(nonatomic , strong) UITableView *tbv;

//内容数组
@property (nonatomic , strong) NSArray *touImagArr;
@property (nonatomic , strong) NSArray *titleArr;

//导航渐变view
@property (nonatomic ,strong) UIView *Jbview;


//文字
@property(nonatomic,strong) UITextView * userNameTextField;

@property(nonatomic,strong) MyInfoModelResult * infoModel;

@property(nonatomic,strong) infoModel * model;

@end

@implementation peopleMesViewController

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    
    self.navigationController.navigationBar.hidden = NO;
    
}

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    UserModel *user = [UserModel sharedInstance:UserKey0];
    if ([UtilTools isBlankString:user.token]) {
            [[AppDelegate shareAppDelegate] setLoginViewController];
        return;
    }
    //个人信息约束
    [self setTouXotherFrame];
    self.navigationController.navigationBar.hidden = NO;
    [self loadData];
}
-(void)loadData{
    UserModel *user = [UserModel sharedInstance:UserKey0];
    NSDictionary *dic = @{
        @"token":user.token
    };
    __weak typeof(self) weakSelf = self;
    [[NetWorkManager sharedManager] postJSON:@"api/cv/list" parameters:dic success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if ([responseObject[@"code"] isEqualToNumber:@200]) {
            weakSelf.infoModel = [MyInfoModelResult yy_modelWithJSON:responseObject[@"result"]];
            dispatch_async(dispatch_get_main_queue(), ^{
                userGender = self.infoModel.userGender;
                userAge = self.infoModel.userAge;
                educationGraduationYear = self.infoModel.educationGraduationYear;
                [self.tbv reloadData];
            });
        }
        else
        {
            dispatch_async(dispatch_get_main_queue(), ^{
                //                 [HWProgressHUD showMessage:responseObject[@"message"]];
            });
        }
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    //左侧导航按钮重写
//    self.navigationController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"backButton"] style:UIBarButtonItemStylePlain target:self action:@selector(BackClick)];
    [self.navigationItem setHidesBackButton:YES];
    [self.navigationController.navigationItem setHidesBackButton:YES];
    [self.navigationController.navigationBar.backItem setHidesBackButton:YES];
    
    [self.view removeAllSubviews];
    
    
    UserModel *user = [UserModel sharedInstance:UserKey0];
    if ([UtilTools isBlankString:user.token]) {
        [[AppDelegate shareAppDelegate] setLoginViewController];
    }
    
    
    _touImagArr = @[@"HTSCITX",@"qunliao",@"sexO",@"cakeO",@"zhiye"];
    _titleArr = @[@"修改昵称",@"修改头像",@"修改性别",@"修改年龄",@"修改职业"];
    
    
    //245 246 251
    self.view.backgroundColor = [UIColor colorWithRed:245/255.0 green:246/255.0 blue:251/255.0 alpha:1.0];
//    [self setNavFrame];
    
    
    //个人信息约束
    [self setTouXotherFrame];
    
    
    [self.view addSubview:self.tbv];
    
    
    
    //确认button
    UIButton *quiTbtn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    ViewRadius(quiTbtn1, KSCHEIGHT(20));
    quiTbtn1.backgroundColor = [UIColor colorWithRed:172/255.0 green:95/255.0 blue:251/255.0 alpha:1.0];
    quiTbtn1.layer.shadowColor = [UIColor colorWithRed:173/255.0 green:172/255.0 blue:172/255.0 alpha:0.14].CGColor;
    quiTbtn1.layer.shadowOffset = CGSizeMake(0,2);
    quiTbtn1.layer.shadowOpacity = 1;
    quiTbtn1.layer.shadowRadius = 4;
    
    CAGradientLayer *glT = [CAGradientLayer layer];
    glT.frame = CGRectMake(0,0,kSCRATIO(250),KSCHEIGHT(40));
    glT.startPoint = CGPointMake(0, 0);
    glT.endPoint = CGPointMake(1, 1);
    glT.colors = @[(__bridge id)[UIColor colorWithRed:247/255.0 green:65/255.0 blue:91/255.0 alpha:1.0].CGColor,(__bridge id)[UIColor colorWithRed:251/255.0 green:171/255.0 blue:102/255.0 alpha:1.0].CGColor];
    glT.locations = @[@(0.0),@(1.0)];
    

    [quiTbtn1.layer addSublayer:glT];
    [self.tbv addSubview:quiTbtn1];
    
    
    [quiTbtn1 setTitle:@"退出登录" forState:UIControlStateNormal];
    quiTbtn1.titleLabel.font = MarkFont(15);
    [quiTbtn1 addTarget:self action:@selector(quiTclick:) forControlEvents:UIControlEventTouchUpInside];
    [quiTbtn1 setTitleColor:kColorFromRGBHex(0xFFFFFF) forState:UIControlStateNormal];
    [quiTbtn1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view); make.bottom.mas_equalTo(self.view.mas_bottom).mas_equalTo(KSCHEIGHT(-170));
        make.width.mas_equalTo(kSCRATIO(250));
        make.height.mas_equalTo(KSCHEIGHT(40));
        
    }];
    
    
}
//-(void)setNavFrame{
//    [self.navigationController.navigationBar removeAllSubviews];
    //设置导航条颜色
//            _Jbview = [[UIView alloc] init];
//            _Jbview.userInteractionEnabled = YES;
        //    Jbview.frame = CGRectMake(0,KSCHEIGHT(-37),kSCRATIO(self.view.frame.size.width),KSCHEIGHT(75));

//            CAGradientLayer *gl = [CAGradientLayer layer];
//            gl.frame = CGRectMake(0,KSCHEIGHT(0),kSCRATIO(self.view.frame.size.width),KSCHEIGHT(82));
//            gl.startPoint = CGPointMake(0, 0);
//            gl.endPoint = CGPointMake(1, 1);
//            gl.colors = @[(__bridge id)[UIColor whiteColor].CGColor];
//            gl.locations = @[@(0.0),@(1.0)];
//            [_Jbview.layer addSublayer:gl];
            
//            [self.navigationController.navigationBar addSubview:_Jbview];
            
            //返回button
//            UIButton *backBtn = [[UIButton alloc] init];
//            [backBtn setBackgroundImage:[UIImage imageNamed:@"backButton"] forState:UIControlStateNormal];
//            [backBtn addTarget:self action:@selector(BackClick) forControlEvents:UIControlEventTouchUpInside];
//    //    [backBtn addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(BackClick)]];
//            [jbTview addSubview:backBtn];
//
//            //标题文字
//            navtitle = [[UILabel alloc] init];
//            navtitle.text = @"个人中心";
//            navtitle.textColor = [UIColor whiteColor];
//            navtitle.font = kFONT(18);
//            [jbTview addSubview:navtitle];
            
//            [_Jbview mas_makeConstraints:^(MASConstraintMaker *make) {
//                make.top.mas_equalTo(KSCHEIGHT(-37));
//                make.width.mas_equalTo(kSCRATIO(self.view.frame.size.width));
//                make.height.mas_equalTo(KSCHEIGHT(82));
//            }];
//            [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//                make.left.mas_equalTo(jbTview.mas_left).mas_equalTo(kSCRATIO(20));
//                make.bottom.mas_equalTo(jbTview.bottom).mas_equalTo(KSCHEIGHT(-15));
//                make.width.mas_equalTo(kSCRATIO(10));
//                make.height.mas_equalTo(KSCHEIGHT(18));
//            }];
//            [navtitle mas_makeConstraints:^(MASConstraintMaker *make) {
//                make.centerX.mas_equalTo(jbTview);
//                make.bottom.mas_equalTo(jbTview.bottom).mas_equalTo(KSCHEIGHT(-8));
//
//            }];
//}
-(void)BackClick{
    jbTview.hidden = YES;
    UIViewController *viewController = self;
    if (viewController) {
        
        [viewController dismissViewControllerAnimated:NO completion:nil];
        
    }
    [self.navigationController popViewControllerAnimated:NO];
}
-(void)setTouXotherFrame{
    jbTview = [[UIView alloc] init];
    jbTview.backgroundColor = [UIColor colorWithRed:172/255.0 green:95/255.0 blue:251/255.0 alpha:1.0];
    jbTview.layer.shadowColor = [UIColor colorWithRed:173/255.0 green:172/255.0 blue:172/255.0 alpha:0.14].CGColor;
    jbTview.layer.shadowOffset = CGSizeMake(0,2);
    jbTview.layer.shadowOpacity = 1;
    jbTview.layer.shadowRadius = 4;
//    jbTview.userInteractionEnabled = YES;

    CAGradientLayer *gl = [CAGradientLayer layer];
    gl.frame = CGRectMake(0,0,kSCRATIO(self.view.frame.size.width),KSCHEIGHT(160));
    gl.startPoint = CGPointMake(0, 0);
    gl.endPoint = CGPointMake(1, 1);
    gl.colors = @[(__bridge id)[UIColor colorWithRed:247/255.0 green:65/255.0 blue:91/255.0 alpha:1.0].CGColor,(__bridge id)[UIColor colorWithRed:251/255.0 green:171/255.0 blue:102/255.0 alpha:1.0].CGColor];
    gl.locations = @[@(0.0),@(1.0)];

    [jbTview.layer addSublayer:gl];
    
    [self.navigationController.navigationBar addSubview:jbTview];
//    self.navigationController.navigationBar.userInteractionEnabled = YES;
    
    [jbTview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(KSCHEIGHT(-37));
        make.left.mas_equalTo(kSCRATIO(0));
        make.right.mas_equalTo(kSCRATIO(0));
        make.width.mas_equalTo(kSCRATIO(self.view.frame.size.width));
        make.height.mas_equalTo(KSCHEIGHT(160));
        
    }];
    
    //返回button
                UIButton *backBtn = [[UIButton alloc] init];
                [backBtn setBackgroundImage:[UIImage imageNamed:@"backButton"] forState:UIControlStateNormal];
                [backBtn addTarget:self action:@selector(BackClick) forControlEvents:UIControlEventTouchUpInside];
            [backBtn addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(BackClick)]];
                [jbTview addSubview:backBtn];
                
                //标题文字
                navtitle = [[UILabel alloc] init];
                navtitle.text = @"个人中心";
                navtitle.textColor = [UIColor whiteColor];
                navtitle.font = kFONT(18);
                [jbTview addSubview:navtitle];
                
    //            [_Jbview mas_makeConstraints:^(MASConstraintMaker *make) {
    //                make.top.mas_equalTo(KSCHEIGHT(-37));
    //                make.width.mas_equalTo(kSCRATIO(self.view.frame.size.width));
    //                make.height.mas_equalTo(KSCHEIGHT(82));
    //            }];
                [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(kSCRATIO(20));
                    make.top.mas_equalTo(KSCHEIGHT(48));
                    make.width.mas_equalTo(kSCRATIO(10));
                    make.height.mas_equalTo(KSCHEIGHT(18));
                }];
                [navtitle mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.centerX.mas_equalTo(jbTview);
                    make.top.mas_equalTo(KSCHEIGHT(45));
                    
                }];
    
    
    //头像
    TouiamgeImageV = [[UIImageView alloc] init];
    [jbTview addSubview:TouiamgeImageV];
            
            
    UserModel *user = [UserModel sharedInstance:UserKey0];
    
    TouiamgeImageV.backgroundColor = [UIColor colorWithRed:248/255.0 green:80/255.0 blue:92/255.0 alpha:1.0];
    //        TouiamgeBtn.image = [UIImage imageNamed:@"customer_service01"];
    //        [TouiamgeBtn addTarget:self action:@selector(headeImgClick:) forControlEvents:UIControlEventTouchUpInside];
    TouiamgeImageV.userInteractionEnabled = YES;
//    [TouiamgeImageV addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(headeImgClick:)]];
            
    //        [TouiamgeBtn setBackgroundImage:[UIImage imageNamed:@"customer_service01"] forState:UIControlStateNormal];
    TouiamgeImageV.image = [UIImage imageNamed:@"customer_service01"];
    TouiamgeImageV.layer.shadowColor = [UIColor colorWithRed:173/255.0 green:172/255.0 blue:172/255.0 alpha:0.14].CGColor;
    if ([UtilTools isBlankString:user.portrait]) {
        [TouiamgeImageV sd_setImageWithURL:[NSURL URLWithString:user.portrait] placeholderImage:[UIImage imageNamed:@"customer_service01"]];
    }
    TouiamgeImageV.layer.shadowOffset = CGSizeMake(0,2);
    TouiamgeImageV.layer.shadowOpacity = 1;
    TouiamgeImageV.layer.shadowRadius = 4;
    ViewRadius(TouiamgeImageV, kSCRATIO(40));
    
    [TouiamgeImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(kSCRATIO(88));
        make.bottom.mas_equalTo(KSCHEIGHT(-10));
        make.width.height.mas_equalTo(kSCRATIO(80));
        
    }];
    //用户昵称button
    UIButton *Namebtn = [[UIButton alloc] init];
            
    NSMutableAttributedString *Nametitle = [[NSMutableAttributedString alloc] initWithString:@"用户昵称"];
    if (![UtilTools isBlankString:user.nickName]) {
                
            Nametitle = [[NSMutableAttributedString alloc] initWithString:user.nickName];;
                
    }
                    
    [Namebtn setAttributedTitle:Nametitle forState:UIControlStateNormal];
    [Namebtn.titleLabel setFont:kFONT(18)];
    //此时如果设置字体颜色要这样
    [Nametitle addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0]  range:NSMakeRange(0,[Nametitle length])];
    [jbTview addSubview:Namebtn];
    
    [Namebtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(TouiamgeImageV.mas_right).mas_equalTo(kSCRATIO(20));
        make.bottom.mas_equalTo(KSCHEIGHT(-40));
    }];
    
    //签名label
    UILabel *qianMlabel = [[UILabel alloc] init];
    qianMlabel.numberOfLines = 0;
    NSMutableAttributedString *qianMString = [[NSMutableAttributedString alloc] initWithString:@"个性签名....." attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFangSC-Regular" size: 15],NSForegroundColorAttributeName: [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.0]}];

    if (![UtilTools isBlankString:user.personalSignature]) {
        qianMString = [[NSMutableAttributedString alloc] initWithString:user.personalSignature attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFangSC-Regular" size: kSCRATIO(12)],NSForegroundColorAttributeName: [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0]}];
    }
    
    qianMlabel.attributedText = qianMString;
    [jbTview addSubview:qianMlabel];
    [qianMlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(TouiamgeImageV.mas_right).mas_equalTo(kSCRATIO(20));
        make.top.mas_equalTo(Namebtn.mas_bottom).mas_equalTo(KSCHEIGHT(0));
        make.width.mas_equalTo(kSCRATIO(160));
    }];
    
    //完成button
    UIButton *saveCbtn = [[UIButton alloc] init];
    [saveCbtn addTarget:self action:@selector(saveClick) forControlEvents:UIControlEventTouchUpInside];
            
    NSMutableAttributedString *saveCtitle = [[NSMutableAttributedString alloc] initWithString:@"完成"];
                    
    [saveCbtn setAttributedTitle:saveCtitle forState:UIControlStateNormal];
    [saveCbtn.titleLabel setFont:kFONT(15)];
    //此时如果设置字体颜色要这样
    [saveCtitle addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0]  range:NSMakeRange(0,[saveCtitle length])];
    [jbTview addSubview:saveCbtn];
    
    [saveCbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(navtitle);
        make.right.mas_equalTo(kSCRATIO(-20));
    }];
    
    
}
-(void)quiTclick:(UIButton *)btn{
    [QuitView gotoLoginViewController];
}

-(void)headeImgClick{
    UserModel *user = [UserModel sharedInstance:UserKey0];
    if ([UtilTools isBlankString:user.token]) {
        [[AppDelegate shareAppDelegate] setLoginViewController];
        return;
    }
    [ZZQAvatarPicker startSelected:^(UIImage * _Nonnull image) {
        if (image) {
//            public static final String bucketName = "kuailejituan";//"hgjt-oss";
//            public static final String objectName = "Image";
            [MessageAlertView showLoading:@""];
            NSData * imageData= UIImageJPEGRepresentation(image, 0.8);
           __block  NSString * fileName = [NSString stringWithFormat:@"%@.%@",[UtilTools getDifferenceUUID],@"jpg"];
            NSString * objectKey = [NSString stringWithFormat:@"Image/%@",fileName];
            
            
            OSSPutObjectRequest * put = [OSSPutObjectRequest new];
            // 必填字段
            put.bucketName = @"kuailejituan";
            put.objectKey = objectKey;
            //    put.uploadingFileURL = [NSURL fileURLWithPath:uploadFilePath];
            put.contentType = [NSString stringWithFormat:@"Image/%@",@"jpg"];
            
            put.uploadingData =imageData; // 直接上传NSData
            // 可选字段，可不设置
            put.uploadProgress = ^(int64_t bytesSent, int64_t totalByteSent, int64_t totalBytesExpectedToSend) {
                // 当前上传段长度、当前已经上传总长度、一共需要上传的总长度
                NSLog(@"%lld, %lld, %lld", bytesSent, totalByteSent, totalBytesExpectedToSend);
            };
            
            //    可以在上传时设置元信息或者其他HTTP头部
            OSSTask * putTask = [[AppDelegate shareAppDelegate].client putObject:put];
            [putTask continueWithBlock:^id(OSSTask *task) {
                
                task = [[AppDelegate shareAppDelegate].client presignPublicURLWithBucketName:@"kuailejituan"
                        
                                                                               withObjectKey:objectKey];
                
                NSLog(@"objectKey: %@", put.objectKey);
                UserModel * user = [UserModel sharedInstance:UserKey0];
                if (!task.error) {
                    fileName = [NSString stringWithFormat:@"https://kuailejituan.oss-cn-hongkong.aliyuncs.com/Image/%@",fileName];
                    NSLog(@"upload object success!");
                    NSDictionary * dic  = [NSDictionary dictionaryWithObjectsAndKeys:
                                           user.token,@"token",
                                           fileName,@"avatar",
                                           nil];
                    @weakify(self);
                    [[NetWorkManager sharedManager] postJSON:@"api/user/updateUser" parameters:dic success:^(NSURLSessionDataTask *task, id responseObject) {
                        dispatch_async(dispatch_get_main_queue(), ^{
                            [MessageAlertView dismissHud];
                            if ([responseObject[@"code"] integerValue]==200) {
                                [TouiamgeImageV sd_setImageWithURL:[NSURL URLWithString:user.portrait] placeholderImage:[UIImage imageNamed:@"customer_service01"]];

                                
                                user.portrait=fileName;
                                
                                [UserModel saveData:UserKey0];
                                dispatch_async(dispatch_get_main_queue(), ^{
                                    [weak_self.tbv reloadData];
                                });
                            }else
                            {
                                dispatch_async(dispatch_get_main_queue(), ^{
                                    [HWProgressHUD showMessage:responseObject[@"message"]];
                                });
                            }
                        });
                        
                        
                    } failure:^(NSURLSessionDataTask *task, NSError *error) {
                        dispatch_async(dispatch_get_main_queue(), ^{
                            [MessageAlertView dismissHud];
                            
                        });
                    }];
                    
                    
                } else {
                    dispatch_async(dispatch_get_main_queue(), ^{
                        [MessageAlertView dismissHud];
                        
                        [HWProgressHUD showMessage:@"图片上传失败,请重新上传"];
                        
                    });
                    NSLog(@"upload object failed, error: %@" , task.error);
                    
                    
                }
                return nil;
            }];
        }
        
    }];
}
-(UITextView *)userNameTextField{
    if (!_userNameTextField) {
        _userNameTextField = [[UITextView alloc] init];
        _userNameTextField.backgroundColor =ColorWhite;
        _userNameTextField.textAlignment = NSTextAlignmentRight;
        _userNameTextField.textColor = kColorFromRGBHex(0xAAAAAA);
        _userNameTextField.font = kFONT(15);
        _userNameTextField.text = @"认真的人生很高级";
        _userNameTextField.delegate = self;
    }
    return _userNameTextField;
}
- (UITableView *)tbv{
    if (!_tbv) {
        _tbv = [[UITableView alloc] initWithFrame:CGRectMake(0, KSCHEIGHT(90), kSCRATIO(self.view.frame.size.width), KSCHEIGHT(self.view.frame.size.height) - KSCHEIGHT(160))];
        _tbv.delegate = self;
        _tbv.dataSource = self;
        
        _tbv.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tbv.separatorColor = [UIColor clearColor];
        
        _tbv.backgroundColor = [UIColor colorWithRed:245/255.0 green:246/255.0 blue:251/255.0 alpha:1.0];
        
        _tbv.scrollEnabled = NO;
        _tbv.sectionFooterHeight = KSCHEIGHT(5);
        _tbv.sectionHeaderHeight = KSCHEIGHT(0);
        
        
    }
    return _tbv;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headrview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, KSCHEIGHT(10))];
    headrview.backgroundColor = [UIColor colorWithRed:245/255.0 green:246/255.0 blue:251/255.0 alpha:1.0];
    return headrview;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return  KSCHEIGHT(10.0);
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 5;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    }
    tableView.rowHeight = KSCHEIGHT(50);
    cell.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    UIImageView *touImageV = [[UIImageView alloc] init];
    touImageV.image = [UIImage imageNamed:_touImagArr[indexPath.row]];
    [cell addSubview:touImageV];
    [touImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(cell);
        make.left.mas_equalTo(kSCRATIO(20));
        make.width.height.mas_equalTo(kSCRATIO(30));
        
    }];
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.text = _titleArr[indexPath.row];
    titleLabel.numberOfLines = 0;
    titleLabel.font = kFONT(kSCRATIO(15));
    titleLabel.textColor = [UIColor colorWithRed:97/255.0 green:97/255.0 blue:97/255.0 alpha:1.0];
    [cell addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(cell);
        make.left.mas_equalTo(touImageV.mas_right).mas_equalTo(kSCRATIO(25));
        
        
    }];
    _tbv.separatorColor = [UIColor lightGrayColor];
    if (indexPath.row == 0) {

        
    }else if (indexPath.row == 2){
        
    }else if (indexPath.row == 3){
        
    }else if (indexPath.row == 4){
        
    }
    
    
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.inputView resignFirstResponder];
    [self.tbv endEditing:YES];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    UserModel *user = [UserModel sharedInstance:UserKey0];
    
    if (indexPath.row == 0) {
        [self.view addSubview:self.userNameTextField];
        NSString *len = user.nickName;
        if (user.nickName.length >= 10) {
            len = [NSString stringWithFormat:@"%@.....",[user.nickName substringToIndex:10]];
        }
        self.userNameTextField.text = len;
        [self.userNameTextField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.left.mas_offset(kSCRATIO(0));
            
            make.bottom.mas_equalTo(self.view.mas_bottom).mas_equalTo(KSCHEIGHT(-40));
            make.height.mas_equalTo(KSCHEIGHT(40));
        }];
    }else if (indexPath.row == 1){
        [self headeImgClick];
    }else if (indexPath.row == 2){
        
    }else if (indexPath.row == 3){
        
    }
    
}
-(void)saveClick{
    UserModel *user = [UserModel sharedInstance:UserKey0];
    NSDictionary *dic = @{
//        @"userSignature":self.inputView.text,
        @"userName":self.userNameTextField.text,
        @"token":user.token
    };
    __weak typeof(self) weakSelf = self;
    [[NetWorkManager sharedManager] postJSON:@"api/user/updateUser" parameters:dic success:^(NSURLSessionDataTask *task, id responseObject) {
        if ([responseObject[@"code"] isEqualToNumber:@200]) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [HWProgressHUD showMessage:@"修改成功"];
//                user.personalSignature = self.inputView.text;
                user.nickName = self.userNameTextField.text;
                [UserModel saveData:UserKey0];
//                UserModel
                [weakSelf.navigationController popViewControllerAnimated:NO];
            });
        }
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
}


@end
